Hash url serialization to ensure hash stability
authorAidan Hobson Sayers <aidanhs@cantab.net>
Tue, 24 May 2016 13:29:52 +0000 (14:29 +0100)
committerAidan Hobson Sayers <aidanhs@cantab.net>
Tue, 24 May 2016 18:29:15 +0000 (19:29 +0100)
Closes #1710

src/cargo/core/source.rs

index 487e421eaa43ebc6987ef9d4a8acaffb21505197..c32e7227f754f285df919af7f4eabbbd4a7d4f9c 100644 (file)
@@ -341,14 +341,17 @@ impl Ord for SourceIdInner {
     }
 }
 
+// The hash of SourceId is used in the name of some Cargo folders, so shouldn't
+// vary. `as_str` gives the serialisation of a url (which has a spec) and so
+// insulates against possible changes in how the url crate does hashing.
 impl hash::Hash for SourceId {
     fn hash<S: hash::Hasher>(&self, into: &mut S) {
         self.inner.kind.hash(into);
         match *self.inner {
             SourceIdInner { kind: Kind::Git(..), ref canonical_url, .. } => {
-                canonical_url.hash(into)
+                canonical_url.as_str().hash(into)
             }
-            _ => self.inner.url.hash(into),
+            _ => self.inner.url.as_str().hash(into),
         }
     }
 }